/*
  学习目标：useEffect监听多个状态的变化

*/

import React, { useState, useEffect } from 'react';

export default function App() {
  const [count, setCount] = useState(0);
  const [msg, setMsg] = useState('hello React');

  // 1. 分开监听
  // useEffect(() => {
  //   document.title = count + msg;
  // }, [count]);

  // useEffect(() => {
  //   document.title = count + msg;
  // }, [msg]);

  // 2. 同时监听
  useEffect(() => {
    document.title = count + msg;
  }, [count, msg]);

  return (
    <div>
      <h1>{count}</h1>
      <h1>{msg}</h1>
      <button onClick={() => setCount(count + 1)}>点我+1</button>

      <button onClick={() => setMsg(msg + '~')}>点我+~</button>
    </div>
  );
}
